<?php


namespace api\channel\jutuike;


use api\channel\meituan\alliance\Seckill;
use app\middleware\MeituanCityNameToCityId;
use app\model\CouponOrderSid;

class MeituanJutuikeSeckillUnion extends ActivityJutuikeChannle
{

    public $baseUrl = 'http://api.act.jutuike.com';

    protected $params = [];


    public function seckillShowInfo(){

        $cityName = $this->params['city_name'] ?? '';
        if ($cityName) {
            $this->params["cityId"] = (new Seckill())->getCityIdByCityName($cityName);
        }


        $url = $this->baseUrl . '/mtfx/seckill_showinfo';

        $defaults = [
            'pub_id' => $this->pubId,
            'cityId' => $this->params["cityId"] ?? MeituanCityNameToCityId::MEITUAN_DDEFAULT_CITYID
        ];

        $data = [];

        $data = handleParameters($data,$defaults, $this->params);

        $res = curlPost($url, $data);

        $res = json_decode($res, true);

        if ($res['code'] == 1){
            $res['code'] = 200;
            $res['msg'] = $res['data'];
        }

        return $res;
    }

    /**
     *秒杀列表
     */
    public function seckillList($args){

        $sid = (new CouponOrderSid())->generateNew(PRODUCT_SECKILL_SERV);

        $url = $this->baseUrl . '/mtfx/seckill_list';
//        $request->setLat($this->params['lat'] ?? 39.918018);
//        $request->setLng($this->params['lng'] ?? 116.397034);
        $defaults = [
            'sid' => $sid,
            'pub_id' => $this->pubId,
            'cityId' => $args['cityId']??62,
            'phone' => '15080260817',
            'os' => '99',
            'showId' => $args['showId'],
            'lat' => $args['lat']??39.918018,
            'lng' => $args['lng']??116.397034,
            'page' => $args['page']??1,
        ];

        $data = [
            'apikey' => $this->apikey,
        ];


        $data = handleParameters($data,$defaults,$args);

        $res = curlPost($url, $data);

        $res = json_decode($res, true);

        if ($res['code'] == 1){
            $res['code'] = 200;
            $res['msg'] = $res['data'];
        }
        return $res;
    }

}